<template>
  <div class="common-edit">
    <script id="editor" type="text/plain" style="width: 100%"></script>
  </div>
</template>
<script>
    export default {
        name: "UE",
        data() {
            return {
                editor: null,
                defaultConfig: {}
            };
        },
        props: ['catchData', 'config', 'htmlContent'], // 接收父组件的方法
        beforeCreate() {
            setTimeout(() => {
                const _this = this;
                let config = Object.assign({}, this.defaultConfig, this.config)
                this.editor = UE.getEditor("editor", config); // 初始化UE
                this.editor.addListener("ready", function () {
                    _this.editor.setContent(_this.htmlContent); // 确保UE加载完成后，放入内容。
                });
                this.editor.addListener("contentChange", () => {
                    this.catchData(this.editor.getContent());
                });
                this.isEnd = true;
            });
        },
        methods: {
            getInit(htmlContent) {
                const _this = this;
                setTimeout(()=>{
                    _this.editor.setContent(htmlContent);
                },500)
            },
            //重置
            reset() {
                const _this = this;
                setTimeout(()=>{
                    _this.editor.setContent('');
                },500)
            },
        },
        destroyed() {
            this.editor.destroy();
        }
    };
</script>
